package business.inhospitalqc;

import com.alibaba.fastjson.JSONObject;
import com.esotericsoftware.yamlbeans.YamlException;
import common.Data;
import common.RunCaseJson;
import common.Yaml;
import io.restassured.RestAssured;
import io.restassured.response.Response;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.log4j.Logger;
import utils.GetFileMess;
import utils.YamlReadUtil;

import java.io.FileNotFoundException;

import static common.Login.login;
import static common.TestStep.requestAndRespondBody;

public class CreateTemplateResult {
    Logger log = Logger.getLogger(CreateTemplateResult.class);
//    CreateTemplate createTemplate=new CreateTemplate();
    public static final String system = "env.properties";
    Data data = login();


    /**
     * @param templateId  api-sourcedata/dmp/template/create的datas
     * @return java.lang.String
     * @Description: 数据集 - 新增
     * @author gujinle
     * @date 2021-05-06 17:58
     */
    public String  CreateModelResult(String templateId) throws FileNotFoundException, ConfigurationException, YamlException {
//        String templateId= createTemplate.CreateModel(i);
        String path=new GetFileMess().getValue("ymlPath",system);
        Yaml yaml= YamlReadUtil.getLocatorMap(path,this.getClass().getName());
        JSONObject json = new JSONObject();
        json.put("access_token", data.getAccessToken());
        json.put("authToken", data.getAccessToken());
        json.put("uniqu_no", data.getUniquNo());
        json.put("operatorId", data.getUserId());
        json.put("authUserId", data.getUserId());
        json.put("templateId", templateId);
        log.info("请求参数：" + json.toString());
        Response response = RunCaseJson.runCase(json, "post", yaml.getUri());
        String jsonStr = response.asString();
        String url = RestAssured.baseURI + ":" + RestAssured.port + RestAssured.basePath +  yaml.getUri();
        requestAndRespondBody(url,json,jsonStr);
        log.info("响应报文：" + jsonStr);
        return templateId;
    }
}
